package cn.iocoder.yudao.module.member.controller.app.major;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.member.controller.admin.major.vo.MajorPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.major.vo.MajorRespVO;
import cn.iocoder.yudao.module.member.controller.admin.major.vo.MajorSaveReqVO;
import cn.iocoder.yudao.module.member.controller.admin.majorobtain.vo.MajorObtainRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.major.MajorDO;
import cn.iocoder.yudao.module.member.dal.dataobject.majorobtain.MajorObtainDO;
import cn.iocoder.yudao.module.member.service.major.MajorService;
import cn.iocoder.yudao.module.member.service.majorobtain.MajorObtainService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户App - 专业")
@RestController
@RequestMapping("/member/major")
@Validated
public class AppMajorController {
    @Resource
    private MajorObtainService majorObtainService;
    @Resource
    private MajorService majorService;

    @GetMapping("/getMajorObtainDO")
    @Operation(summary = "获得专业表-就业方向")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<List<MajorObtainDO>> getMajorObtainDO(@RequestParam("majorId") Long majorId) {
        List<MajorObtainDO> majorObtain = majorObtainService.getMajorObtainDO(majorId);
        return success(majorObtain);
    }

    @GetMapping("/oneList")
    @Operation(summary = "获得专业列表一级层级")
    public CommonResult<List<MajorRespVO>> getMajorOneList() {
        List<MajorDO> pageResult = majorService.getMajorOneList();
        return success(BeanUtils.toBean(pageResult, MajorRespVO.class));
    }

    @GetMapping("/twoList")
    @Operation(summary = "获得专业列表二级层级")
    public CommonResult<List<MajorRespVO>> getMajorTwoList(@RequestParam Long pid) {
        List<MajorDO> pageResult = majorService.getMajorTwoList(pid);
        return success(BeanUtils.toBean(pageResult, MajorRespVO.class));
    }

    @GetMapping("/threeList")
    @Operation(summary = "获得专业列表三级层级")
    public CommonResult<List<MajorRespVO>> getMajorThreeList(@RequestParam Long pid) {
        List<MajorDO> pageResult = majorService.getMajorThreeList(pid);
        return success(BeanUtils.toBean(pageResult, MajorRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得专业列表")
    public CommonResult<List<MajorRespVO>> getMajorList(@RequestParam(required = false) String name) {
        List<MajorRespVO> pageResult = majorService.getMajorList(name);
        return success(BeanUtils.toBean(pageResult, MajorRespVO.class));
    }

    @GetMapping("/get")
    @Operation(summary = "获得专业详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<MajorRespVO> getMajor(@RequestParam("id") Long id) {
        MajorDO major = majorService.getMajor(id);
        return success(BeanUtils.toBean(major, MajorRespVO.class));
    }
}